import intiaData from '../state'

function shoppingcarReducer(state=intiaData.shoppingcar,action){
  switch (action.type){
      case "PinkProduct":
            let newItem=[...state.item]
            let product=action.product
            let exist=false
            newItem.map((item)=>{
            if(item.id===product.id){
                exist=true
                return {...product,count:item.count++}
            }
            else{
                return item
            }
            })
            if(!exist){
                newItem.push({...product,count:1})
            }
            return {...state,item:newItem};
      default:
          return state
  }
}
export default shoppingcarReducer